/**
 * 
 */
package com.ekingstar.framework.action;

import java.util.List;

import org.apache.struts2.config.Action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.Element;
import com.ekingstar.framework.domain.Role;
import com.ekingstar.framework.security.UserUtil;
import com.ekingstar.framework.service.IRoleService;
import com.ekingstar.framework.service.IUserRoleService;

/**
 * 
 *
 */

@SuppressWarnings("serial")
@Action(name="myRight",namespace="/user")
public class MyRightAction extends ActionSupport{
	
	private IRoleService roleService;
	private IUserRoleService userRoleService;
	@Element(Role.class)
	private List<Role> roles;
	
	private List hasroles;
	
	
	private String id;
	
	public String execute(){
		this.hasroles = roleService.getRoleByUserId(UserUtil.getCurrentUserId());
		return "list";
	}
	/*public String listQueryUserPage(){
		this.page = userService.getUserlistByUser(user,pageNo, pageSize);
		return "list";
	}*/
	
	public String addRole(){
		this.roles = roleService.getAllRoles();
		this.hasroles = roleService.getRoleByUserId(UserUtil.getCurrentUserId());
		if (roles != null && hasroles != null){
			for (int i = 0; i < roles.size();i++){
				Role r = roles.get(i);
				int index = hasroles.indexOf(r);
				System.out.println(index);
				if (index >= 0){
					Role hasRole = (Role)hasroles.get(index);
					r.setCanGrant(hasRole.getCanGrant());
					r.setCanUse(hasRole.getCanUse());
				}
			}
		}
		return "addrole";
	}
	
	
	
	public List getHasroles() {
		return hasroles;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	
	public String tree(){
		
		return "tree";
	}
	public List<Role> getRoles() {
		return roles;
	}
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public IRoleService getRoleService() {
		return roleService;
	}
	public void setRoleService(IRoleService roleService) {
		this.roleService = roleService;
	}
	public IUserRoleService getUserRoleService() {
		return userRoleService;
	}
	public void setUserRoleService(IUserRoleService userRoleService) {
		this.userRoleService = userRoleService;
	}

}
